home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000100_icon-group-sender_Tue Dec 9 12:35:09 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id hB9JYj008755
  4.     for icon-group-addresses; Tue, 9 Dec 2003 12:34:45 -0700 (MST)
  5. Message-Id: <200312091934.hB9JYj008755@baskerville.CS.Arizona.EDU>
  6. From: Steve Wampler <swampler@noao.edu>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: Desperately in need of help
  9. Date: Tue, 09 Dec 2003 09:02:22 -0700
  10. X-Complaints-To: abuse@noao.edu
  11. User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)
  12. To: icon-group@cs.arizona.edu
  13. X-Spam-Status: No, hits=-3.0 required=5.0
  14.     tests=BAYES_20,QUOTED_EMAIL_TEXT,REFERENCES,USER_AGENT
  15.     version=2.55
  16. X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
  17. Errors-To: icon-group-errors@cs.arizona.edu
  18. Status: RO
  19.  
  20. On Mon, 08 Dec 2003 23:10:48 -0800, Afgncaap5 wrote:
  21. ...
  22. > Anyway, I'm working towards creating a very simple, basic program that
  23. > will create data tables.  Each cell of the table is named after a
  24. > letter of the alphabet, and each cell contains the number of times
  25. > that this letter has been encountered in the input.  After this stage,
  26. > a random number generator is used to find a number between 0 and 1,
  27. > and each of the numbers in the cells are to be divided by the sum
  28. > total of all of the cells.  The program will then select a letter of
  29. > the alphabet based on all of this.
  30. > Now, my prof keeps telling me that there's an error in the code but is
  31. > absolutely refusing to tell me where the error is, what the error is
  32. > doing, and how I can go about fixing it.  Can someone help me? 
  33. > Included is a copy of the material that I'm working with.
  34.  
  35. Have you tried compiling the code yet?  There's definitely
  36. a syntax error - there is no keyword &alphabet.  I suspect
  37. you mean &lcase again.  This is a bit worrisome, as it means
  38. you haven't tried running the program yourself yet...
  39.  
  40. There are also some logic flaws, from what I understand of
  41. the problem.  For example:
  42.  
  43. As it's written now, the entire program can be rewritten as:
  44.  
  45.    procedure main()
  46.        write("z")
  47.    end
  48.  
  49. which probably isn't what you want!   (My guess is that this
  50. is a work in progress, where you'll be adding more to the
  51. program as you get this part running.)
  52.  
  53. Finally, the statement:
  54.  
  55.     &random := 0
  56.  
  57. probably isn't doing what you want.  That does not
  58. randomize a timer.  In fact, 0 is the initial value
  59. of &random, so the above line isn't really doing anything.
  60.  
  61. If you want a different sequence of random numbers generated
  62. each time you run the program, you'll have to assign a
  63. unique (different) seed to &random each time you run the
  64. program.
  65.  
  66.  
  67.  
  68.  
  69. > procedure main()
  70. >     &random :=0 #randomizes the timer
  71. >     primary := table(0)  #Creates a table with all values equal to zero
  72. >     
  73. >     test := string(&lcase)  # Creates a string based on all lower-case
  74. > letters
  75. >     every primary[!test] +:=1  #Goes through every letter in the alphabet
  76. > and increments it by one
  77. >     sum := 0  # creates a value of sum equal to zero
  78. >     every x := !&lcase do
  79. >         sum +:= primary[x]
  80. >     
  81. >     cumcounts := 0
  82. >     cumprob := table(0.0000)
  83. >     every x:=!&lcase do{
  84. >         cumcounts +:= primary[x]
  85. >         cumprob[x]:=(cumcounts*1.0000)/(sum    *1.0000)
  86. >     }
  87. >     
  88. >     
  89. >     randnum := ?0
  90. >     every x := !&alphabet do {
  91. >         if randnum <= primary[x] then { 
  92. >             letter := x
  93. >         }
  94. >     }
  95. >     write(x)
  96. >             
  97. > end
  98.  
  99.